package it.mozzicato.apkwizard.dto;

/**
 * @author Roberto Mozzicato
 *
 */
public class BaseResource implements StatusObject {
	private ResourceTypes type;
	private String name;
	private String originalValue;
	private String value;

	public BaseResource(ResourceTypes type, String name, String value) {
		this.type = type;
		this.name = name;
		this.value = value;
	}

	public ResourceTypes getType() {
		return type;
	}

	public void setType(ResourceTypes type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}
	
	public String getOriginalValue() {
		return originalValue;
	}

	public void setOriginalValue(String oldValue) {
		this.originalValue = oldValue;
	}

	public ResourceStatus getStatus() {
		if(value != null) {
			if(originalValue != null) {
				if(value.equals(originalValue))
					return ResourceStatus.ORIGINAL;
				return ResourceStatus.UPDATED;
			}
			return ResourceStatus.INSERTED;
		}
		else if(originalValue == null)
			return ResourceStatus.ORIGINAL;
		return ResourceStatus.DELETED;	
	}	

	@Override
	public boolean equals(Object obj) {
		BaseResource otherRes = (BaseResource) obj;
		
		return type==null && name == null && otherRes.type==null && otherRes.name==null || 
			type != null && name != null && type.equals(otherRes.type) && name.equals(otherRes.name);
	}
}
